package model;

import java.io.Serializable;
import javax.persistence.*;

import dao.MessageDao;

import java.util.Date;
import java.util.List;


/**
 * The persistent class for the view database table.
 * 
 */
@Entity
@NamedQuery(name="View.findAll", query="SELECT v FROM View v")
public class View implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	private String name;

	private String info;

	private String location;

	private int price;

	@Temporal(TemporalType.DATE)
	private Date time;

	private String vcname;

	//bi-directional many-to-one association to Message
	@OneToMany(mappedBy="view")
	private List<Message> messages;

	//bi-directional many-to-one association to Vroute
	@OneToMany(mappedBy="view")
	private List<Vroute> vroutes;

	public View() {
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getInfo() {
		return this.info;
	}

	public void setInfo(String info) {
		this.info = info;
	}

	public String getLocation() {
		return this.location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public int getPrice() {
		return this.price;
	}

	public void setPrice(int price) {
		this.price = price;
	}

	public Date getTime() {
		return this.time;
	}

	public void setTime(Date time) {
		this.time = time;
	}

	public String getVcname() {
		return this.vcname;
	}

	public void setVcname(String vcname) {
		this.vcname = vcname;
	}

	public List<Message> getMessages() {
		return this.messages;
	}
	public List<Message> getMessages1() {
		return 	MessageDao.getMessagsByView(this.name);
	}

	public void setMessages(List<Message> messages) {
		this.messages = messages;
	}

	public Message addMessage(Message message) {
		getMessages().add(message);
		message.setView(this);

		return message;
	}

	public Message removeMessage(Message message) {
		getMessages().remove(message);
		message.setView(null);

		return message;
	}

	public List<Vroute> getVroutes() {
		return this.vroutes;
	}

	public void setVroutes(List<Vroute> vroutes) {
		this.vroutes = vroutes;
	}

	public Vroute addVroute(Vroute vroute) {
		getVroutes().add(vroute);
		vroute.setView(this);

		return vroute;
	}

	public Vroute removeVroute(Vroute vroute) {
		getVroutes().remove(vroute);
		vroute.setView(null);

		return vroute;
	}

}